/*************************************************************************
> File Name: WaterMarkHal.cpp
> Author: 
> Mail: 
> Created Time: 2021年12月20日 星期一 17时30分40秒
************************************************************************/
#include <cutils/log.h>
#include <hardware/hardware.h>
#include "AlgorithmModule.h"
#include "Algorithm.h"
#include "WMarkFactory.h"
#include "AbstractFactory.h"

namespace camera {
namespace algorithm {

    static AbstractFactory *globalFactory = NULL;
    static Algorithm *globalAlgorithm = NULL;

    int algorithm_init(algorithm_type_enum type)
    {
        ALOGI("client-leo %s ->", __func__);
        switch(type) {
            case WMarkAlgorithm:
            globalFactory = new WMarkFactory();
            globalAlgorithm = globalFactory->createWaterMarkAlgModule();
            break;
            default:
            break;
        }
        ALOGI("%s <-", __func__);
        return 0;
    }

    int algorithm_handle(algorithm_info_t info)
    {
        if (!globalAlgorithm) {
            ALOGE("%s error! globalAlgorithm == NULL", __func__);
            return -1;
        }
        return globalAlgorithm->handle(info);
    }

    struct algorithm_device_t algorithm_device = {
        .commn = {},
        .algorithm_init = algorithm_init,
        .algorithm_handle = algorithm_handle,
    };

    int algorithm_open(const struct hw_module_t* module, const char* id,
                       struct hw_device_t** device)
    {
        *device = (struct hw_device_t *)&algorithm_device;
        return 0;
    }

} // algorithm
} // camera

hw_module_methods_t method = {
    .open = camera::algorithm::algorithm_open,
};

hw_module_t HAL_MODULE_INFO_SYM={
    .tag = HARDWARE_MODULE_TAG,
    .version_major = 1,
    .version_minor = 0,
    .name = "camera algorithm module",
    .author = "leo@mega",
    .id = ALGORITHM_HMI_ID,
    .methods = &method,
    .dso = 0,
    .reserved = {},
};
